package com.nimitz.web.controller.module.demo;

import cn.hutool.core.util.ObjectUtil;
import com.nimitz.common.core.controller.BaseController;
import com.nimitz.common.core.page.TableDataInfo;
import com.nimitz.common.utils.bean.BeanUtils;
import com.nimitz.module.demo.domain.DemOrder;
import com.nimitz.module.demo.domain.DemUser;
import com.nimitz.module.demo.domain.dto.DemOrderDto;
import com.nimitz.module.demo.service.IDemoOrderDtoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/module/orderDto")
@Api(tags = "演示模块-订单")
public class DemOrdOrderDtoController extends BaseController {

    @Resource
    IDemoOrderDtoService demoOrderDtoService;

    /**
     * 根据条件查询订单列表（含分页）
     *
     * @param orderDto     订单dto
     * @return 订单集合
     */
    @PostMapping("/list")
    @ApiOperation(value = "订单查询")
    public TableDataInfo list(@RequestBody DemOrderDto orderDto) {
        DemOrder order = new DemOrder();
        BeanUtils.copyBeanProp(order, orderDto);
        if (ObjectUtil.isNotEmpty(orderDto)){
            DemUser user = new DemUser();
            user.setUserName(orderDto.getUser().getUserName());
            order.setUser(user);
        }
        startPage();
        List<DemOrder> list = demoOrderDtoService.selectOrderListDto(order);
        return getDataTable(list);
    }
}
